phpParser = $parserFactory->create(ParserFactory::ONLY_PHP7); $this->nodeTraverser = new NodeTraverser(); $this->nodeTraverser->addVisitor(new AssignedToNodeVisitor()); } /** * @api tests * @return Node[] */ public function parseFile(string $filePath) : array { $fileContent = FileSystem::read($filePath); return $this->parseString($fileContent); } /** * @return Node[] */ public function parseString(string $fileContent) : array { $fileContent = $this->ensureFileContentsHasOpeningTag($fileContent); $hasAddedSemicolon = \false; try { $nodes = $this->phpParser->parse($fileContent); } catch (Throwable $exception) { // try adding missing closing semicolon ; $fileContent .= ';'; $hasAddedSemicolon = \true; $nodes = $this->phpParser->parse($fileContent); } if ($nodes === null) { return []; } $nodes = $this->restoreExpressionPreWrap($nodes, $hasAddedSemicolon); return $this->nodeTraverser->traverse($nodes); } private function ensureFileContentsHasOpeningTag(string $fileContent) : string { if (\strncmp(\trim($fileContent), 'expr]; } }